package com.ruoyi.system.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysAccountInfo;
import com.ruoyi.system.service.ISysAccountInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 账户信息Controller
 * 
 * @author zhangjf
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/info")
public class SysAccountInfoController extends BaseController
{
    @Autowired
    private ISysAccountInfoService sysAccountInfoService;

    /**
     * 查询账户信息列表
     */
    @RequiresPermissions("system:info:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAccountInfo sysAccountInfo)
    {
        startPage();
        List<SysAccountInfo> list = sysAccountInfoService.selectSysAccountInfoList(sysAccountInfo);
        return getDataTable(list);
    }

    /**
     * 导出账户信息列表
     */
    @RequiresPermissions("system:info:export")
    @Log(title = "账户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAccountInfo sysAccountInfo)
    {
        List<SysAccountInfo> list = sysAccountInfoService.selectSysAccountInfoList(sysAccountInfo);
        ExcelUtil<SysAccountInfo> util = new ExcelUtil<SysAccountInfo>(SysAccountInfo.class);
        util.exportExcel(response, list, "账户信息数据");
    }

    /**
     * 获取账户信息详细信息
     */
    @RequiresPermissions("system:info:query")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId)
    {
        return success(sysAccountInfoService.selectSysAccountInfoByAccountId(accountId));
    }

    /**
     * 新增账户信息
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "账户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAccountInfo sysAccountInfo)
    {
        return toAjax(sysAccountInfoService.insertSysAccountInfo(sysAccountInfo));
    }

    /**
     * 修改账户信息
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "账户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAccountInfo sysAccountInfo)
    {
        return toAjax(sysAccountInfoService.updateSysAccountInfo(sysAccountInfo));
    }

    /**
     * 删除账户信息
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "账户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds)
    {
        return toAjax(sysAccountInfoService.deleteSysAccountInfoByAccountIds(accountIds));
    }

    /**
     * 操作 冻结，停用，解冻，启用
     */
    @RequiresPermissions("system:info:operate")
    @Log(title = "账户信息", businessType = BusinessType.OTHER)
    @PostMapping("/operate")
    public AjaxResult operate(@RequestBody SysAccountInfo sysAccountInfo)
    {
        return toAjax(sysAccountInfoService.updateSysAccountStatus(sysAccountInfo));
    }
}
